namespace MoreLinq;

using System;
using System.Collections.Generic;

static partial class MoreEnumerable
{
    /// <summary>
    /// Returns a sequence consisting of the head elements and the given tail element.
    /// 返回一个列表,由头元素和尾元素一起拼接而成的列表
    /// </summary>
    /// <typeparam name="T">Type of sequence</typeparam>
    /// <param name="head">All elements of the head. Must not be null.</param>
    /// <param name="tail">Tail element of the new sequence.</param>
    /// <returns>A sequence consisting of the head elements and the given tail element.</returns>
    /// <remarks>This operator uses deferred execution and streams its results.</remarks>
#if NET471_OR_GREATER || NETSTANDARD1_6_OR_GREATER || NETCOREAPP2_0_OR_GREATER
    public static IEnumerable<T> Append<T>(IEnumerable<T> head, T tail)
#else
        public static IEnumerable<T> Append<T>(this IEnumerable<T> head, T tail)
#endif
    {
        if (head == null) throw new ArgumentNullException(nameof(head));
        return head is PendNode<T> node
            ? node.Concat(tail)
            : PendNode<T>.WithSource(head).Concat(tail);
    }
}
